package top.kaoshanji.p2ch18a;

import top.kaoshanji.p2ch18a.support.FixedDelayTask1;
import top.kaoshanji.p2ch18a.support.LongRunningTask1;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * 代码清单-p2ch18a-524页a：多线程的定时任务执行服务示例
 * author kaoshanji
 * ^_^
 * create time 2025/2/27 17:51
 */
public class ScheduledFixedDelay {

    public static void main(String[] args) {

        ScheduledExecutorService timer = Executors.newScheduledThreadPool(10);

        timer.schedule(new LongRunningTask1(), 10, TimeUnit.MILLISECONDS);
        // 再次执行，此任务就不会被上面的任务延迟了
        timer.scheduleWithFixedDelay(new FixedDelayTask1(), 100, 1000, TimeUnit.MILLISECONDS);

    }


}
